#!/bin/bash

menu(){
	echo "1.backup /var/log"
	echo "2.Specify the backup file backup path"
	echo "3.According to the condition to find file backup"
	echo "4.exit"
	read -p "please input your chioce:" option
}

#1.backup /var/log
backup_log(){
	tar zcf /bak/log/`date +%F_%T`.tar.gz /var/log &>/dev/null
	find /bak/log/* -mtime +7 -exec rm -rf {} \;
}

#2.Specify 
Specify_backup(){
	read -p "please input a ansolute path:" path_way
	b_time=`date +%F`
	echo $b_time
	file_name=`echo "$path_way"|awk -F/ '{print $NF}'`
	[ -d /bak/$b_time ]||mkdir /bak/$b_time
	tar zcf /bak/$b_time/${file_name}_`date +%F_%T`.tar.gz $path_way &>/dev/null
}

main(){
	[ -d /bak/log ]||mkdir -p /bak/log
	while :
	do
		menu
		case $option in 
		1)
			backup_log
			;;
		2)
			Specify_backup
			;;
		3)
			;;
		4)
			exit
			;;
		*)
			exit
			;;
		esac
	done
}
main
